<template>
  <template v-if="_rules.max_array > 1 && _info.field_type !== 'table'">
    <Item
      v-for="(it, index) in eachItems"
      :key="index"
      :formInfo="formInfo"
      :value="it"
      isEach
      :topExpose="topExpose"
      v-bind="$attrs"
    />
  </template>
  <Item v-else :formInfo="formInfo" :topExpose="topExpose" v-bind="$attrs" />
</template>

<script setup>
import { getInfo, getRules, initDynamicNum } from '../const';
import Item from './Item';

const props = defineProps({
  formInfo: {
    type: Object,
    default: () => {}
  },
  topExpose: {
    type: Object,
    default: () => {}
  }
});

const _info = computed(() => getInfo(props.formInfo));
const _rules = computed(() => getRules(props.formInfo));

const eachItems = computed(() => {
  const min_array = _rules.value.min_array;
  const max_array = _rules.value.max_array;
  const _value = _info.value.value ?? [];
  initDynamicNum(_value, min_array, max_array, '');
  return _value;
});
</script>

<style lang="scss" scoped></style>
